revise the schema default type not null - #3752
Conversation
|
@congbobo184 while I am ok if we decide to remove allow null from set by default, my only concern is this ix NOT a backwards compatible change. |
merlimat
left a comment
There was a problem hiding this comment.
This is breaking backward compatibility.
There needs to be a migration plan that allows us to identify that a schema was created with an earlier version of the client library and thus will let through a one-time no-check migration to the new default.
|
Since the Python schema generation is following the current behavior of the Java client. We also need to change the defaults there. Again, with migration path in mind. |
|
@congbobo184 @jerrypeng @merlimat : I don't think we should attempt to involve any data migration between schemas, that will be a nightmare. what I would suggest here:
so there are nothing else to be changed. but the documentation should be updated to highlight |
|
Adding the flag and leave I think though that using Regarding the migration path, I'm not referring to migrate the schema definition, but rather to allow a one-time "incompatible" schema evolution marked with a version in pulsar schema registry. |
supporting "incompatible" schema can't really be done using POJO schemas. we can support that using the generic schema stuffs that I recently work on. but there are still a lot of work to complete in that piece before we can claim we are ready to take such "incompatible" migration. |
|
In this case the problem is that, if we change the default setting, the schema extracted from a given POJO will change. The user defined will still be the same though, as the data serialized by it. |
the user defined will be still the same. that's fine. The other way around is working - you are okay to use a AllowNull schema to deserialize the data serialized by a NOT AllowNull schema. With that being explained, if we are using POJO schema, we can't really just "migrate" the schema in schema registry (or it is very very tricky to do so). We can do it by using MultiVersionedGenericSchema which I introduced a few days ago. For each message, it will be using the right schema to deserialize the record into a |
|
@sijie @congbobo184 @merlimat if we are removing AllowNull or allowing the flag to be configurable, should we also do it for JSONSchema: |
|
@jerrypeng I am not sure we need to do it for JSON. because there is no real schema in JSON data. every field in a json struct is optional, no? |
|
Thinking on this a bit more, I believe a better approach is to let the user specify the Avro schema definition directly, either in form of schema object or in json string. That is because:
The recommendation in the docs would be to pass the schema if you already have one. |
+1 on supporting specifying avro schema (via schema object or json). that's one of the schema tasks in my TODO list related schema builder. Although I think it should be done in a separate PR. |
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * http://www.apache.org/licenses/LICENSE-2.0 |
There was a problem hiding this comment.
format license header
| */ | ||
| static <K, V> Schema<KeyValue<K, V>> KeyValue(Class<K> key, Class<V> value, SchemaType type) { | ||
| return DefaultImplementation.newKeyValueSchema(key, value, type); | ||
| return DefaultImplementation.newKeyValueSchema(key, value, type,true); |
| */ | ||
| static <K, V> Schema<KeyValue<K, V>> KeyValue(Class<K> key, Class<V> value) { | ||
| return DefaultImplementation.newKeyValueSchema(key, value, SchemaType.JSON); | ||
| return DefaultImplementation.newKeyValueSchema(key, value, SchemaType.JSON,true); |
| } | ||
|
|
||
| public static <T> Schema<T> newAvroSchema(Class<T> clazz) { | ||
| public static <T> Schema<T> newAvroSchema(Class<T> clazz,Boolean allowNull) { |
| () -> (Schema<T>) getStaticMethod("org.apache.pulsar.client.impl.schema.AvroSchema", "of", Class.class) | ||
| .invoke(null, clazz)); | ||
| () -> (Schema<T>) getStaticMethod("org.apache.pulsar.client.impl.schema.AvroSchema", "of", Class.class,Boolean.class) | ||
| .invoke(null, clazz,allowNull)); |
|
run Integration Tests |
2 similar comments
|
run Integration Tests |
|
run Integration Tests |
|
run java8 tests |
|
run Integration Tests |
|
run java8 tests |
|
run Integration Tests |
1 similar comment
|
run Integration Tests |
|
run Integration Tests |
4 similar comments
|
run Integration Tests |
|
run Integration Tests |
|
run Integration Tests |
|
run Integration Tests |
|
run Integration Tests |
Fix #3741 Support define not not allow null field in schema Add not allow null field schema verify Does this pull request potentially affect one of the following parts: If yes was chosen, please highlight the changes Dependencies (does it add or upgrade a dependency): (no) The public API: (no) The schema: (yes) The default values of configurations: (no) The wire protocol: (no) The rest endpoints: (no) The admin cli options: (no) Anything that affects deployment: (no)
|
Merged in 2.3.1 at |
Motivation
Fix #3741
Modifications
Support define not not allow null field in schema
Verifying this change
Add not allow null field schema verify
Does this pull request potentially affect one of the following parts:
If yes was chosen, please highlight the changes
Dependencies (does it add or upgrade a dependency): (no)
The public API: (no)
The schema: (yes)
The default values of configurations: (no)
The wire protocol: (no)
The rest endpoints: (no)
The admin cli options: (no)
Anything that affects deployment: (no)